#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x << " = " << x << endl)

#define rep(i,n) for (int i=0; i<n; i++)

#define f first
#define s second
#define mp make_pair

#define ll long long
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0

#define sqr(x) ((x)*(x))
int cups[3];
int from, to;
int tmp;

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	scanf("%d", &tmp);
	tmp--;

	rep(i,3) cups[i]=0;
	cups[tmp]=1;

	TRACE(
		rep(i,3) printf("%d ", cups[i]);
		printf("\n"); 
	)

	rep(i,3) {
		scanf("%d %d", &from, &to);
		from--; to--;
		tmp = cups[from];
		cups[from]=cups[to];
		cups[to]=tmp;
	
		TRACE(
			rep(i,3) printf("%d ", cups[i]);
			printf("\n"); 
		)
	}

	rep(i, 3) {
		if (cups[i]==1) {
			printf("%d\n", i+1);
			break;
		}
	}	

	return 0;
}
